package second.greedy;

public class Solution08 {
    public int jump(int[] nums) {
        if (nums.length == 1) return 0;
        int res = 0;
        int cover = 0;
        int max = 0;
        for (int i = 0; i < nums.length; i++) {
            max = Math.max(max, i + nums[i]);
            if (max >= nums.length - 1) {
                res++;
                break;
            }
            if (i == cover) {
                res++;
                cover = max;
            }
        }
        return res;
    }
}

